package cn.stylefeng.guns.modular.production.productionOrder.controller;

import cn.stylefeng.guns.modular.production.productionOrder.entity.Order;
import cn.stylefeng.guns.modular.production.productionOrder.pojo.request.OrderRequest;
import cn.stylefeng.guns.modular.production.productionOrder.service.OrderService;
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.List;
import java.util.Map;

/**
 * 生产订单表控制器
 *
 * @author panl
 * @since 2023/12/15 11:29
 */
@RestController
@ApiResource(name = "生产订单表")
public class OrderController {

    @Resource
    private OrderService orderService;

    /**
     * 添加生产订单表
     *
     * @author panl
     * @since 2023/12/15 11:29
     */
    @PostResource(name = "添加生产订单表", path = "/productionOrder/add")
    public ResponseData<Order> add(@RequestBody @Validated(OrderRequest.add.class) OrderRequest orderRequest) {
        orderService.add(orderRequest);
        return new SuccessResponseData<>();
    }
    /**
     * 关闭生产订单表
     *
     * @author panl
     * @since 2023/12/15 11:29
     */
    @PostResource(name = "关闭生产订单表", path = "/productionOrder/close")
    public ResponseData<?> close(@RequestBody @Validated(OrderRequest.delete.class) OrderRequest orderRequest) {
        orderService.close(orderRequest);
        return new SuccessResponseData<>();
    }
    /**
     * 关闭生产订单表
     *
     * @author panl
     * @since 2023/12/15 11:29
     */
    @PostResource(name = "批量关闭生产订单表", path = "/productionOrder/batchClose")
    public ResponseData<?> batchClose(@RequestBody @Validated(OrderRequest.delete.class) OrderRequest orderRequest) {
        orderService.batchClose(orderRequest);
        return new SuccessResponseData<>();
    }
    /**
     * 删除生产订单表
     *
     * @author panl
     * @since 2023/12/15 11:29
     */
    @PostResource(name = "删除生产订单表", path = "/productionOrder/delete")
    public ResponseData<?> delete(@RequestBody @Validated(OrderRequest.delete.class) OrderRequest orderRequest) {
        orderService.del(orderRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 批量删除生产订单表
     *
     * @author panl
     * @since 2023/12/15 11:29
     */
    @PostResource(name = "批量删除生产订单表", path = "/productionOrder/batchDelete")
    public ResponseData<?> batchDelete(@RequestBody @Validated(BaseRequest.batchDelete.class) OrderRequest orderRequest) {
        orderService.batchDelete(orderRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 编辑生产订单表
     *
     * @author panl
     * @since 2023/12/15 11:29
     */
    @PostResource(name = "编辑生产订单表", path = "/productionOrder/edit")
    public ResponseData<?> edit(@RequestBody @Validated(OrderRequest.edit.class) OrderRequest orderRequest) {
        orderService.edit(orderRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 查看生产订单表详情
     *
     * @author panl
     * @since 2023/12/15 11:29
     */
    @GetResource(name = "查看生产订单表详情", path = "/productionOrder/detail")
    public ResponseData<Order> detail(@Validated(OrderRequest.detail.class) OrderRequest orderRequest) {
        return new SuccessResponseData<>(orderService.detail(orderRequest));
    }

    /**
     * 获取生产订单表列表
     *
     * @author panl
     * @since 2023/12/15 11:29
     */
    @GetResource(name = "获取生产订单表列表", path = "/productionOrder/list")
    public ResponseData<List<Order>> list(OrderRequest orderRequest) throws ParseException {
        return new SuccessResponseData<>(orderService.findList(orderRequest));
    }

    /**
     * 获取生产订单表列表（带分页）
     *
     * @author panl
     * @since 2023/12/15 11:29
     */
    @GetResource(name = "获取生产订单表列表（带分页）", path = "/productionOrder/page")
    public ResponseData<PageResult<Order>> page(OrderRequest orderRequest) throws ParseException {
        return new SuccessResponseData<>(orderService.findPage(orderRequest));
    }


    /**
     * 获取生产订单表列表（带分页）
     *
     * @author panl
     * @since 2023/12/15 11:29
     */
    @GetResource(name = "获取生产订单表列表（带分页）", path = "/productionOrder/material")
    public ResponseData<Map> material(OrderRequest orderRequest)  {
        return new SuccessResponseData<Map>(orderService.material(orderRequest));
    }

}
